package com.huawei123.hasee.cniao5store.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.huawei123.hasee.cniao5store.utils.LogUtils;

import java.util.List;

/**
 * 项目名称：Cniao5Store
 * 类描述：ViewPager与Fragment绑定
 * 创建人：Administrator
 * 创建时间：2017/10/25 0025 下午 3:56
 * 修改人：Administrator
 * 修改时间：2017/10/25 0025 下午 3:56
 * 修改备注：
 */

public class FixPagerAdapter extends FragmentStatePagerAdapter {

    private List<Fragment> fragments;
    private String[] titles;

    public FixPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setFragments(List<Fragment> Fragments) {
        this.fragments = Fragments;
    }

    public void setTitle(String[] titles) {
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = null;
        try {
            fragment = (Fragment) super.instantiateItem(container, position);
        } catch (Exception e) {
            LogUtils.debug("选项卡与ViewPager绑定失败");
        }

        return fragment;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}
